package cn.bytecollege.service;

import cn.bytecollege.model.Goods;
import cn.bytecollege.model.UserDetail;
import cn.bytecollege.util.FileUpLoad;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

@Service
@Log4j2
public class FileUploadService {
    @Autowired
    private PersonalService personalService;
    @Autowired
    private CommunityService communityService;
    public Integer fileUpload(String path,MultipartFile file,Integer userId) {
        String imagePath = FileUpLoad.fileUpLoad(path, file);
        if (imagePath.equals("上传失败")){
            return -1;
        }else {
            UserDetail userDetail = UserDetail.builder().userId(userId).userImage(imagePath).build();
            personalService.modUserDetailByUserId(userDetail);
            return 1;
        }
    }
    public String fileUploadGoodsImages(String path,MultipartFile file){
        String imagePath = FileUpLoad.fileUpLoad(path, file);
        if ("上传失败".equals(imagePath)){
            return "上传失败";
        }else {
            return imagePath;
        }
    }
}
